// pages/userStatistics/UserDeatils/accountDetail.js
const Controllers = require('../../controllers/Controller').controller;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    globalStype:'',
    moneyData:{},
    amountList:[],
    outList:[],
    value:{
      genre:0,
      shopId:"",
      amountType:0,
      pageNumber:1,
      types:"0,1,3,6,7,9"
    },
    tabItem:0,
    selectIndex:0,
    lastPage:false,
    accountId:"",
    accountRelationId:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    if(options.userId){
      this.setData({
        'value.accountId':options.userId,
        accountRelationId:options.accountRelationId
      })
    }

    if(wx.getStorageSync('shopId')){
      this.setData({
        shopId:wx.getStorageSync('shopId'),
        'value.shopId':wx.getStorageSync('shopId')
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
      this.getAmountHistory()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.getIncomeOrCost()
  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function (e) {
  
  // },
  // 进行tab跳转选项
  selectTab(e){
    let index=e.currentTarget.dataset.index
    this.setData({
      selectIndex:index
    })
    if(index==0){
      this.setData({
        "value.genre":0,
        "value.pageNumber":1,
        "value.lowLine":'',
      })
    }else if(index==1){
      this.setData({
        "value.genre":1,
        "value.pageNumber":1,
        "value.lowLine":0,
        "value.types":""
      })
    }else if(index==2){
      this.setData({
        "value.genre":1,
        "value.pageNumber":1,
        "value.lowLine":1,
        "value.types":"3"
      })
    }
    this.getAmountHistory()
  },


  //获取充值消费记录
  getAmountHistory(){
    let value=this.data.value
    // let value2=this.data.value2
    Controllers.amountHistory(value).then(res=>{
      this.setData({
        amountList:res.data.list,
        lastPage:res.data.lastPage
      })
    })
  },

  //跳转账单详情
  toTransactionDetail(e){
    let orderNo=e.currentTarget.dataset.orderno
    let genre=e.currentTarget.dataset.genre
    let type=e.currentTarget.dataset.type
    let name=e.currentTarget.dataset.name
    let head=e.currentTarget.dataset.head
  
    wx.navigateTo({
      url: '/pages/Index/transactionRecord/transactionDetails?orderNo='+orderNo+"&genre="+genre+"&type="+type+"&name="+name+"&head="+head+"&accountId="+this.data.value.accountId,
    })
  },


  //下滑获取充值或者消费的记录
  getIncomeOrCost(){
    if(this.data.lastPage==false){
      let value=this.data.value
      value.pageNumber=value.pageNumber+1
      this.setData({
        value:value
      })
      Controllers.amountHistory(value).then(res=>{
        let list1=this.data.amountList;
        let list2=res.data.list;
        let cList=list1.concat(list2);

        this.setData({
          amountList:cList,
          lastPage:res.data.lastPage
        })
      })
    }
  }
})